package com.cutie.entry.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cutie.core.util.ServletUtils;
import com.cutie.entry.model.EntryDictionary;
import com.cutie.entry.service.EntryDictionaryService;
import com.mysql.jdbc.StringUtils;

public class FetchEntryServlet extends HttpServlet {

	EntryDictionaryService entryDictionaryService = new EntryDictionaryService();
	
	public void init() throws ServletException {
		entryDictionaryService = new EntryDictionaryService();
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ServletUtils.setEncoding(request, response);
		PrintWriter out = response.getWriter();
		
		try{
			
			String entryName = (String)request.getParameter("entryName");
			if(StringUtils.isNullOrEmpty(entryName)){
				out.println("参数不合法");
				return;
			}
			
			List<EntryDictionary> list = entryDictionaryService.findEntriesByEntryName(entryName);
			out.println(list);
			
		}catch(Exception e){
			out.println("服务器错误!");
			e.printStackTrace();
		}finally{
			out.flush();
			out.close();
		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request,response);
	}

}
